﻿<!-- CV前端代码 -->
<template>
	<div >
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
					<el-form :model="queryParams" ref="queryForm" :inline="true">
						<el-row :gutter="35">
						  <!-- <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
			              <el-form-item label="类型">
							<el-select v-model="queryParams.unitType"  >
						    <el-option
						      v-for="item in options"
						      :key="item.value"
						      :label="item.label"
						      :value="item.value"
						    />
						  </el-select>
			              </el-form-item>
			              </el-col> -->
			              <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" >
			              <el-form-item label="站台">
			              <el-input v-model="queryParams.num" clearable placeholder="站台"/>
			              </el-form-item>
			              </el-col>
						 
                
			          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20 search-actions">
         
			          <div>
			          <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
			          <el-button type="primary" plain icon="ele-Search" @click="handleQuery" v-auth="'unitCv:page'"> 查询 </el-button>
			          </div>
			          </el-col>
			      </el-row>
			      </el-form>
	   </el-card>
		<el-card shadow="hover" style="margin-top: 8px">
			<el-table
				:data="tableData.slice((tableParams.page-1)*tableParams.pageSize,(tableParams.page-1)*tableParams.pageSize+tableParams.pageSize)"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
				border="">
				<el-table-column type="index" label="序号" width="55" align="center" fixed="" />
				 <el-table-column prop="num" label="站台号" width="150" show-overflow-tooltip="" />
				 <el-table-column  label="模式" width="80" show-overflow-tooltip="" >
					<template #default="scope">
						<el-tooltip content="0：手动 1：自动" placement="top" effect="light">
							<span tooltip="">{{ scope.row.mode }}</span>  
                       </el-tooltip>
					    
			       </template>
				 </el-table-column>
				 <el-table-column prop="equipNum" label="设备编码" width="100" show-overflow-tooltip="" />
				 <el-table-column prop="bcrReady" label="请求扫码" width="100" show-overflow-tooltip="" 
					 :filters="[
					 	{ text: '已请求', value: 1 },
					 	{ text: '未请求', value: 0 },
					 ]"
	      :filter-method="filterReady"
	      filter-placement="bottom-end">
		  <template #default="scope">
				        <el-tag
				          :type="scope.row.bcrReady === 1 ? 'success' : 'info'"
				          disable-transitions >{{ scope.row.bcrReady == 1 ? '已请求' : '未请求' }}
						</el-tag>
				      </template>
		</el-table-column>

		 
		  <el-table-column prop="taskNumber" label="任务号" width="120" show-overflow-tooltip="" />
		  <el-table-column prop="dest" label="目的地" width="120" show-overflow-tooltip="" />
		  <!-- <el-table-column prop="trayType" label="托盘类型" width="100" show-overflow-tooltip="" /> -->
		  <el-table-column  label="存在托盘" width="100"  :filters="[
				  	{ text: '是', value: 1 },
				  	{ text: '否', value: 0 },
				  ]"
	      :filter-method="filterExist"
	      filter-placement="bottom-end">
				      <template #default="scope">
				        <el-tag 
				          :type="scope.row.isExistTray1 === 1 ? 'success' : 'info'"
				          disable-transitions >{{ scope.row.isExistTray1 == 1 ? '是' : '否' }}
						</el-tag>
				      </template>
				    </el-table-column>
				
				  <el-table-column  label="托盘" width="150"  :filters="[
				  	{ text: '有', value: 1 },
				  	{ text: '无', value: 0 },
				  ]"
	      :filter-method="filterTray"
	      filter-placement="bottom-end">
				      <template #default="scope">
				       {{ scope.row.tray1 }}-{{ scope.row.tray2 }}
				      </template>
				    </el-table-column>
				<el-table-column prop="error" label="报警代码" width="100" show-overflow-tooltip="" />

				<el-table-column  label="扫码数" width="100" show-overflow-tooltip="" >

					<template #default="scope">
						<el-tooltip :content="scope.row.bcrReadTime" placement="top" effect="light">
						
                      
				        <el-tag 
				          :type="scope.row.maxReadBcr === scope.row.readOkBcr ? 'success' : 'info'"
				          disable-transitions >{{ scope.row.maxReadBcr }}/{{ scope.row.readOkBcr }}
						</el-tag>
					</el-tooltip>
				      </template>
					
				</el-table-column>
				<el-table-column prop="trayOnTime" label="停留分钟" width="100" show-overflow-tooltip="" />
				<el-table-column  label="错误信息" show-overflow-tooltip="" :filters="[
				  	{ text: '报错', value: '报错' }
				  
				  ]"
	      :filter-method="filterMsg"
	      filter-placement="bottom-end">
			      <template #default="scope" >
			   
					<el-tag v-if="scope.row.message" 
			          :type="scope.row.message =='success'?'success':'danger'"
			          disable-transitions >{{ scope.row.message }}
					</el-tag>
			      </template>
			    </el-table-column>
				  
				<el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" >
					<template #default="scope">
						
						<el-button  size="small" text="" type="primary" @click="cvControl(scope.row)" v-auth="'unitCv:control'"> 调度 </el-button>
						<el-button v-if="scope.row.isExistTray1"  size="small" text="" type="primary" @click="callBcrRead(scope.row)" v-auth="'unitCv:control'">  扫码</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableData.length"
				:page-sizes="[10, 20, 50, 100]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
			
			<cvControlDialog
			    ref="cvControlDialogRef"
			    :title="cvControlDialogTitle"
			    @reloadTable="handleQuery"
      />

	  <cvTagDialog :tagtype="'cv'" :tagnumber="tagNumber"
			    ref="cvTagDialogRef"
			    			    
      />
		</el-card>
	</div>

	
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { ElMessageBox, ElMessage } from "element-plus";
	import { auth } from '/@/utils/authFunction';
	//import { formatDate } from '/@/utils/formatTime';

	import cvControlDialog from '/@/views/main/grpc/unitCv/component/cvControlDialog.vue'
	import cvTagDialog from '/@/views/main/grpc/unitCv/component/cvTagDialog.vue'
	import { WriteEquip } from "/@/api/main/equipTag";

	import { GetProcessData } from '/@/api/main/grpcServer';


	// cv调度弹窗
	const cvControlDialogRef = ref();
	// cv点位详情弹窗
	const cvTagDialogRef=ref();

	// cv调度弹窗标题
	const cvControlDialogTitle = ref("");
	const tagNumber = ref(0);
    const loading = ref(false);
    const tableData = ref<any>([]);
    const queryParams = ref<any>(
	{

		unitType:4
	});
	
	const tableParams = ref({
	page: 1,
	pageSize: 10,
	total: 0,
	});

	// 改变页面容量
const handleSizeChange = (val: number) => {
  tableParams.value.pageSize = val;
 
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
  tableParams.value.page = val;
 
};

	
	// 查询操作
	const handleQuery = async () => {
	loading.value = true;
	let para={
		nums:queryParams.value.num,
		providerType:6	
		};
	
	var res = await GetProcessData(para);
	tableData.value = res.data.result ?? [];
	tableParams.value.total = res.data.result?.length;
	loading.value = false;
};

const filterReady = (value: number, row: any) => {
  return row.isBcrReady=value;
}

const filterExist = (value: number, row: any) => {
  return row.isExistTray1=value;
}

const filterTray = (value: number, row: any) => {
    if(value==1){
	   return row.tray1 || row.tray2;
	}else{
		return !row.tray1 && !row.tray2;
	}
}

const filterMsg = (value: string, row: any) => {
	if(!row.message || row.message=='success'){
		return false;
	}
  return true;
}

// 调度方法
const cvControl=async(row:any)=>{

	cvControlDialogTitle.value = '物流线调度';
	let data={
		num:row.num,
		trayCode:row.tray,
		task:10001
		
	}
	cvControlDialogRef.value.openDialog(data);
};

const callBcrRead=async(row:any)=>{
	let data={
		mode:100,
		equipId:row.equipId,
		protobufType:row.protobufType,
		num:row.num

	};

	await WriteEquip(data);


	ElMessage({
    message: '操作成功.',
    type: 'success',
  });
  };




handleQuery();
</script>


